home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
parcs
/
parcs.lha
/
sample
/
parser-dcg.parcs
< prev
next >
Wrap
Text File
|
1992-06-08
|
831b
|
36 lines
append([],X,X).
append([A|X],Y,[A|Z]) :- append(X,Y,Z).
parse(Sentence,Ptree) :- s(Sentence,[],Ptree).
s(X,Y,s(NP,VP)) :- np(X,Z,NP),vp(Z,Y,VP).
vp(X,Y,vp(V)) :- v(X,Y,V).
vp(X,Y,vp(V,NP)) :- v(X,Z,V),np(Z,Y,NP).
/* vp -> vp, pp is left recursive */
vp(X,Y,vp(VP,PP)) :- append([A|X1],[B|X2],X), vp([A|X1],[],VP),pp([B|X2],Y,PP).
np([he|X],X,np(he)).
np([this|X],X,np(this)).
np([ken|X],X,np(ken)).
np(X,Y,np(N)) :- n(X,Y,N).
np(X,Y,np(D,NP)) :- d(X,Z,D),np(Z,Y,NP).
np(X,Y,np(A,NP)) :- a(X,Z,A),np(Z,Y,NP).
np(X,Y,np(NP,PP)) :- append([A|X1],[B|X2],X), np([A|X1],[],NP),pp([B|X2],Y,PP).
pp(X,Y,pp(P,NP)) :- p(X,Z,P),np(Z,Y,NP).
n([pen|X],X,n(pen)).
n([man|X],X,n(man)).
v([is|X],X,v(is)).
v([has|X],X,v(has)).
a([black|X],X,a(black)).
a([this|X],X,a(this)).
p([with|X],X,p(with)).
d([a|X],X,d(a)).
d([the|X],X,d(the)).